package com.lycos.ludrien.client;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;

import com.lycos.ludrien.utils.FileUtil;

public class ReadQueries {
	public static HashMap<String, Requete> hashmap_queries = new HashMap<String, Requete>();
	public static HashMap<String, RequetePonderee> hashmap_queriesP = new HashMap<String, RequetePonderee>();
	
	public static void readFileQueries(){
		ArrayList<File> queriesXML = FileUtil.getCollection("xml", "Queries");
		SAXBuilder saxBuilder = new SAXBuilder();
		Element root;
		Document document = new Document();
		for (File file : queriesXML) {

			try {
				document = saxBuilder.build(file);
			} catch (JDOMException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}

			root = document.getRootElement();
			for (Element element : root.getChildren("query")){
				hashmap_queries.put(element.getAttributeValue("id"), new Requete(element.getChildText("text")));
				hashmap_queriesP.put(element.getAttributeValue("id"), new RequetePonderee(element.getChildText("text")));
			}
		}
	}
}